<?php

class System_model extends Model
{
	function __construct()
	{
		parent::__construct();
	}

	function SaveSystem()
	{
		if($this->in_var['request_method'] == 'post')
		{

			if($this->in_var['SiteName'])
			{
				$this->addData('Value',$this->in_var['SiteName']);
				$this->where('Var',"SiteName");
				$this->dataUpdate('system');
			}

			if($this->in_var['SiteUrl'])
			{
				$this->addData('Value',$this->in_var['SiteUrl']);
				$this->where('Var',"SiteUrl");
				$this->dataUpdate('system');
			}


			if($this->in_var['TemplatePath'])
			{
				$this->addData('Value',$this->in_var['TemplatePath']);
				$this->where('Var',"TemplatePath");
				$this->dataUpdate('system');
			}

			if($this->in_var['BackPath'])
			{
				$this->addData('Value',$this->in_var['BackPath']);
				$this->where('Var',"BackPath");
				$this->dataUpdate('system');
			}
			
			if($this->in_var['PublishPath'])
			{
				$this->addData('Value',$this->in_var['PublishPath']);
				$this->where('Var',"PublishPath");
				$this->dataUpdate('system');
			}
			

			if($this->in_var['SaveType'])
			{
				$this->addData('Value',$this->in_var['SaveType']);
				$this->where('Var',"SaveType");
				$this->dataUpdate('system');
			}

			if($this->in_var['Rewrite'])
			{
				$this->addData('Value',$this->in_var['Rewrite']);
				$this->where('Var',"Rewrite");
				$this->dataUpdate('system');
			}


			if($this->in_var['Cache'])
			{
				$this->addData('Value',$this->in_var['Cache']);
				$this->where('Var',"Cache");
				$this->dataUpdate('system');
			}


			if($this->in_var['CacheTime'])
			{
				$this->addData('Value',$this->in_var['CacheTime']);
				$this->where('Var',"CacheTime");
				$this->dataUpdate('system');
			}

			if($this->in_var['UploadPath'])
			{
				$this->addData('Value',$this->in_var['UploadPath']);
				$this->where('Var',"UploadPath");
				$this->dataUpdate('system');
			}

			if($this->in_var['FileSize'])
			{
				$this->addData('Value',$this->in_var['FileSize']);
				$this->where('Var',"FileSize");
				$this->dataUpdate('system');
			}


			if($this->in_var['FileType'])
			{
				$this->addData('Value',$this->in_var['FileType']);
				$this->where('Var',"FileType");
				$this->dataUpdate('system');
			}



			if($this->in_var['WaterMark'])
			{
				$this->addData('Value',$this->in_var['WaterMark']);
				$this->where('Var',"WaterMark");
				$this->dataUpdate('system');
			}


			if($this->in_var['WatermarkImgPath'])
			{
				$this->addData('Value',$this->in_var['WatermarkImgPath']);
				$this->where('Var',"WatermarkImgPath");
				$this->dataUpdate('system');
			}

			if($this->in_var['WatermarkPosition'])
			{
				$this->addData('Value',$this->in_var['WatermarkPosition']);
				$this->where('Var',"WatermarkPosition");
				$this->dataUpdate('system');
			}

			if($this->in_var['PageNum'])
			{
				$this->addData('Value',$this->in_var['PageNum']);
				$this->where('Var',"PageNum");
				$this->dataUpdate('system');
			}

			if($this->in_var['SearchNum'])
			{
				$this->addData('Value',$this->in_var['SearchNum']);
				$this->where('Var',"SearchNum");
				$this->dataUpdate('system');
			}

			if($this->in_var['MovieNum'])
			{
				$this->addData('Value',$this->in_var['MovieNum']);
				$this->where('Var',"MovieNum");
				$this->dataUpdate('system');
			}

			$this->Cache->makeCache('sys');
			return true;

		}

	}


	function clear(){

		if($this->in_var['request_method'] == 'post'){

			//删除系统信息缓存
			if($this->in_var['syscache'] =='1'){

				@unlink('../cache/sys/cache_system_info.php');

			}

			//删除文章分类缓存

			if($this->in_var['categorycache'] =='1'){

				@unlink('../cache/sys/cache_category_info.php');

			}

			//清空缓存目录

			if($this->in_var['dircache'] =='1')
			{

				if ($handle = opendir('../cache/sys')) {

					while (false !== ($file = readdir($handle))) {

						@unlink('../cache/sys/'.$file);
					}

					closedir($handle);
				}
			}

			//清空模板编译目录
			if($this->in_var['comcache'] =='1'){

				if ($handle = opendir('../cache/compile')) {

					while (false !== ($file = readdir($handle))) {
						//echo 'cache'.$file;
						@unlink('../cache/compile/'.$file);
					}

					closedir($handle);
				}
			}

			return true;
			//success('缓存更新成功','index.php?c=system&d=clear');
		}
	}

	function mail()
	{
		if($this->in_var['request_method'] == 'post'){

			if($this->in_var['smtp'])
			{
				$this->addData('Value',$this->in_var['smtp']);
				$this->dataUpdate('system',' Where var = "smtp"');
				$this->cleanData();
			}

			if($this->in_var['port'])
			{
				$this->addData('Value',$this->in_var['port']);
				$this->dataUpdate('system',' Where var = "port"');
				$this->cleanData();
			}

			if($this->in_var['sendmail'])
			{
				$this->addData('Value',$this->in_var['sendmail']);
				$this->dataUpdate('system',' Where var = "sendmail"');
				$this->cleanData();
			}

			if($this->in_var['username'])
			{
				$this->addData('Value',$this->in_var['username']);
				$this->dataUpdate('system',' Where var = "username"');
				$this->cleanData();
			}

			if($this->in_var['password'])
			{
				$this->addData('Value',$this->in_var['password']);
				$this->dataUpdate('system',' Where var = "password"');
				$this->cleanData();
			}

			$this->cache->makeCache('sys');

			goto('index.php?c=system&d=mail&t=mail');
		}
	}

}

?>